package com.oocl.operator;

import com.oocl.model.Customer;
import com.oocl.rcm.Entry;

public class Convert {
	public static Customer convert(String imformation){
		Customer customer = new Customer();
		String[] info = imformation.split(",");
		for (int i = 0; i < info.length; i++) {
			String[] str = info[i].split(":");
			if(str.length==2){
				String key = str[0];
				String value = str[1];
				setting(customer,key,value);
			}else{
				Entry.showError();
			}
			
		}	
		customer.setId(Entry.index + "");
		
		Entry.index++;
		return customer;	
	}
	
	public static void setting(Customer customer,String key, String value){
		if(key.equals("name")){
			customer.setName(value);
		}else if(key.equals("sex")){
			customer.setSex(value);
		}else if(key.equals("birthday")){
			customer.setBirthday(value);
		}else if(key.equals("address")){
			customer.setAddress(value);
		}else if(key.equals("call")){
			customer.setCall(value);
		}
	}
	
}
